package com.iptv.grape.bu.imp;


import android.view.KeyEvent;

import com.iptv.grape.BaseActivity;
import com.iptv.grape.bu.AppState;
import com.iptv.grape.bu.GrapeContext;
import com.iptv.grape.bu.IKeyEventPorc;
import com.iptv.grape.domain.Channel;
import com.iptv.grape.event.EventArgs;
import com.iptv.grape.event.data.LiveData;
import com.iptv.grape.util.AppConstant;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.video.XMediaPlayer;

import org.greenrobot.eventbus.EventBus;

// 退出时移模式
@AppState(isShowLiveMenu = false,curPlayType = "Live",curLiveType = "Time", isTimeLiveUI = false, keyVals = {4})
public class QuitTimeLiveMode implements IKeyEventPorc {
    @Override
    public void onKeyDownEvent(BaseActivity context, XMediaPlayer mediaPlayer, GrapeContext grapeContext, KeyEvent event) {
        QuitTimeLiveMode.quit(context,mediaPlayer,grapeContext,event);
    }

    public static void quit(BaseActivity context, XMediaPlayer mediaPlayer, GrapeContext grapeContext, KeyEvent event){
        grapeContext.setCurLiveType("Live");
        AppLog.getCurLog().out("退出时移1");
        Channel channel = grapeContext.getChannelDLinkList().getCurChannel();
        channel.playChannel();
        grapeContext.removeTimeLiveFragment(context);

        LiveData liveData = new LiveData(channel, "5", "23", "0");
        EventBus.getDefault().post(new EventArgs(AppConstant.DataLive, AppConstant.DataAcquisition, liveData));


    }

    public static void quit(BaseActivity context, XMediaPlayer mediaPlayer, GrapeContext grapeContext, KeyEvent event,Channel toChannel){
        grapeContext.setCurLiveType("Live");
        AppLog.getCurLog().out("退出时移2");
        Channel channel = grapeContext.getChannelDLinkList().getCurChannel();
        if(toChannel!=null)
            channel =toChannel;
        channel.playChannel();
        grapeContext.removeTimeLiveFragment(context);

        LiveData liveData = new LiveData(channel, "5", "23", "0");
        EventBus.getDefault().post(new EventArgs(AppConstant.DataLive, AppConstant.DataAcquisition, liveData));


    }
}
